package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.biz.ApplicationListBiz;
import cn.hrlly.tao2shou.biz.ApplicationListBizImpl;
import cn.hrlly.tao2shou.domain.ApplicationList;
import cn.hrlly.tao2shou.listener.OnApplicationListListener;
import cn.hrlly.tao2shou.view.view_interface.ApplicationListView;

/**
 * User: gengliang
 * Date: 2016-01-31
 * Time: 11:17
 */

public class ApplicationListPresenterImpl implements ApplicationListPresenter,OnApplicationListListener {

    private ApplicationListBiz applicationListBiz;
    private ApplicationListView applicationListView;

    public ApplicationListPresenterImpl(ApplicationListView applicationListView,Context context){
        this.applicationListBiz=new ApplicationListBizImpl(this,context);
        this.applicationListView=applicationListView;
    }

    @Override
    public void showApplicationList() {
        ApplicationList applicationList=new ApplicationList();
        applicationList.setApplicationType(applicationListView.getApplicationType());
        applicationListBiz.getNetApplicationList(applicationList);
    }

    @Override
    public void showCacheApplicationList() {
        int n=applicationListView.getApplicationType();
        ApplicationList applicationList=new ApplicationList();
        switch (n){
            case 0:
                applicationList=applicationListBiz.getCacheBuyerApplicationList();
                break;
            case 1:
                applicationList=applicationListBiz.getCacheSellerApplication();
                break;
        }
        if(applicationList!=null)
            applicationListView.showListView(applicationList);
    }

    @Override
    public void showApplicationListSucc(ApplicationList applicationList) {
        applicationListView.showListView(applicationList);

        //将数据缓存
        if(applicationListView.getApplicationType()==0)
            applicationListBiz.saveCacheBuyerApplicationList(applicationList);
        else
            applicationListBiz.saveCacheSellerApplicationList(applicationList);
    }

    @Override
    public void showApplicationListFail(String errorMessage) {
        applicationListView.showMessage(errorMessage);
    }

    @Override
    public void showApplicationListFail(int errorMessage) {
        applicationListView.showMessage(errorMessage);
    }
}
